package com.myhome.controller;

import com.dianping.cat.Cat;
import com.dianping.cat.message.spi.internal.DefaultMessageTree;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    private static String TestDemain = "MyTestDomain";

    @RequestMapping("test01")
    public String test01() {

        DefaultMessageTree tree = (DefaultMessageTree) Cat.getManager().getThreadLocalMessageTree();
        tree.setDomain(TestDemain);
        Cat.logEvent("err", "EnventName");
        return "test00001";
    }

    @RequestMapping("test02")
    public String test02() {
        Cat.logEvent("err", "EnventName");
        for (int i = 0; i < 10; i++) {
            Cat.logMetricForCount("RequestNum");
        }
        return "test000022";
    }

    @RequestMapping("test03")
    public String test03() {
        Cat.logEvent("err", "MyEnventName");
        for (int i = 0; i < 30; i++) {
            Cat.logMetricForSum("RequestNum", 12);
        }
        return "test0000333";
    }

    @RequestMapping("test")
    public void test() {
        new Thread(() -> excute()).start();
    }

    private void excute(){
        while (true) {
            try {
                Thread.sleep(1000 * 60);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("...........执行...........");
            test01();
            test02();
            test03();
        }
    }
}
